<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>添加单元信息</title>

<base target="_self" />

<link href="<%=path1%>/ht/Styles/css.css" rel="stylesheet" type="text/css" />
<link href="<%=path1%>/ht/Styles/ts_css.css" rel="stylesheet" type="text/css" />
<script src="<%=path1%>/ht/Scripts/My97DatePicker/WdatePicker.js"
	type="text/javascript"></script>
<script src="<%=path1%>/ht/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="<%=path1%>/ht/Scripts/IndexManager.js" type="text/javascript"></script>
<!-- <script src="Scripts/jquery.min.js" type="text/javascript" ></script>
<script src="Scripts/jquery.validate.min.js" type="text/javascript" ></script> -->
<script type="text/javascript">

//添加单元信息
    function addAjax(){
    	//alert("走了");
    	$.ajax({
    		data:{
    			build_id:$("#build_id").val(),
    	        project_id:$("#project_id").val(),
    	        unit_code:$("#unit_code").val(),
    	        room_count:$("#room_count").val()
    		},
    		type:"post",
    		datatype:'json',
    		url:"<%=path1%>/qt/ht/unit/addUnit.do",
    		error:function(data){
    			alert("出错了");
    		},
    		success:function(data){
    			//alert("添加单元成功");
    			window.location.href="<%=path1%>/qt/ht/unit/selectAll.do";
    		}
    	});
     }
    </script> 

<%-- 	$.ajax({
    	url:"<%=path1%>/qt/ht/build/selectAlls.do",
        datatype:'json', 
        error:function(data){  
            alert("出错了！！");  
       },  
       success:function(data){
    	   //alert("成功了");	    	   
    	   //alert(data.msg.length);
       var len=data.msg.length;  //遍历出来楼栋里的长度（没有删除的）
       //var select = document.getElementById("build_id");//取楼栋ID
       //var build_id =$("#buiid").val();//去当前jsp页面的楼栋ID
       //alert(build_id);
       var html="";
       if(len>0){
    	   data.msg.forEach(function(e){  
    		    if(e.build_id == build_id){
    		     html+="<option value="+e.build_id+" selected='selected'>"+e.build_name+"</option>";
 	    	   }else{
 	    		  html+="<option value="+e.build_id+">"+e.build_name+"</option>";
 	    	   }
    		}) 
    		$("#build_id").append(html);
         }
       }
	});
 --%>

<%-- 	$.ajax({
    	url:"<%=path1%>/qt/ht/project/selectAlls.do",
        datatype:'json', 
        error:function(data){  
            alert("出错了！！");  
       },  
       success:function(data){
       var len=data.msg.length;
       var html="";
       if(len>0){
    	   data.msg.forEach(function(e){  
    		    if(e.project_id == project_id){
    		     html+="<option value="+e.project_id+" selected='selected'>"+e.project_name+"</option>";
 	    	   }else{
 	    		  html+="<option value="+e.project_id+">"+e.project_name+"</option>";
 	    	   }
    		}) 
    		$("#project_id").append(html);
         }
       }
	}); --%>

  <script type="text/javascript">
  function breaks(){
	  window.location.href="<%=path1%>/qt/ht/unit/selectAll.do";
  }
  </script>
<script type="text/javascript">
	function build_ids() {
		var build_id = document.getElementById("build_id").value;		
		if (build_id == ""||build_id==null) {
			//alert("楼栋编号不能为空");
			//build_id.focus();
			return false;
		}
		return true;
	}

	function project_ids() {
		var project_id = $("#project_id").val();
		if (project_id == ""||project_id==null) {
			//alert("项目编号不能为空");
			//$("#project_id").focus();
			return false;
		}
		return true;
	}

	function unit_codes() {
		var unit_code = $("#unit_code").val();
		if (unit_code == "" || unit_code==null) {
			//alert("单元号不能为空");
			//$("#unit_code").focus();
			return false;
		}
		return true;
	}

	function room_counts() {
		var room_count = $("#room_count").val();
		if (room_count == "" ||room_count==null) {
			//alert("房间数量不能为空");
			//$("#room_count").focus();
			return false;
		}
		return true;
	}
	
</script> 

<script type="text/javascript">
    function danji(){
    	//alert("走你");
    	if(build_ids()==true & project_ids()==true & unit_codes()==true & room_counts()==true){
    		addAjax();
    	}else{
    		alert("红色星号为必填项！");
    	}
    }
</script>

</head>
<body>

<form id="form1" method="post">
		<div id="divTwo">
			<table width="100%" border="0" cellpadding="3" cellspacing="3"
				class="table_list1">
				<h2 align="center">添加单元信息</h2>
				
				<tr>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 项目名称:
					</td>
					<td width="10%" class="table_list1_style2"><select type="text"
						 id="project_id" onblur="project_ids()" style="width: 140px">
						
						<c:forEach items="${proj}" var="a">
					       <option value="${a.project_id}">${a.project_name}</option>
					    </c:forEach>
								 
						 </select>
						 </td>
				</tr>
				
				<tr>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 楼栋名称:
					</td>
					<td width="10%" class="table_list1_style2"><select type="text"
						id="build_id" onblur="build_ids()" style="width: 140px">	
						 
						 <c:forEach items="${bu}" var="a">
					       <option value="${a.build_id}">${a.build_name}</option>
					    </c:forEach>
						 					 
				         </select>
						 </td>
				</tr>

				<tr>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 单元号：
					</td>
					<td width="10%" class="table_list1_style2"><input type="text"
						id="unit_code" name="unit_code" onblur="unit_codes()"></td>					
				</tr>
				
	    		<tr>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 房间数量：
					</td>
					<td width="10%" class="table_list1_style2"><input type="text"
						id="room_count" name="room_count" onblur="room_counts()"></td>					
				</tr>
				
				<tr>
					<td width="50%" class="table_list1_style1">

						<p></p> <input type="button" id="send" value="添加" tabindex="1"
						class="button" onclick="danji();" /> &nbsp;
					</td>
					<td width="50%" class="table_list1_style2">

						<p></p> <input type="button" class="button" value="返回"
						tabindex="1" onclick="breaks();" />
					</td>
					<td class="table_list1_style1">&nbsp;</td>
				</tr>
			</table>
		</div>
	</form>
</body>
</html>